package object2;

/**
 * 继承
 * class 子类 extends 父类 {
 *
 * }
 */
public class Extends {

    public static void main(String[] args) {

        /*
            继承-》解决代码复用的问题
            子类会自动拥有父类定义的属性和方法
            父类又叫超类，基类
            子类又叫派生类
         */
        Pupil pupil = new Pupil();
        pupil.name = "张三";
        pupil.age = 18;
        pupil.testing();
        pupil.setScore(50);
        pupil.showInfo();

        System.out.println("======");

        Graduate graduate = new Graduate();
        graduate.name = "李四";
        graduate.age = 23;
        graduate.testing();
        graduate.setScore(80);
        graduate.showInfo();

    }
}

class Student{

    //共有属性
    public String name;

    public int age;

    private double score;

    //共有的方法
    public void setScore(double score) {
        this.score = score;
    }

    public void showInfo() {
        System.out.println("学生名 " + name + " 年龄 " + age + " 成绩 " + score);
    }

}

class Pupil extends Student{

    public void testing() {
        System.out.println("小学生" + name + "正在考小学数学..");
    }
}

class Graduate extends Student{

    public void testing() {
        System.out.println("大学生" + name + "正在考小学数学..");
    }
}